package org.zsl.mqdemo;

import com.rabbitmq.client.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ComsumerTestor {


    private static String QUEUE_NAME = "fanout_queue_email";


    public static void main(String[] args) throws IOException, TimeoutException {


        Connection connection = RabbitConnectionUtil.getConnection();

        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);

        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

                String message = new String(body);

                System.out.println("当前序号是:" + "1");
                System.out.println("message from " + QUEUE_NAME +" is :" + message);
            }
        };


        channel.basicConsume(QUEUE_NAME,true,consumer);


    }
}
